use "/Users/jimgolby/Desktop/ZB - Confidence Book/Technical Appendix/Data Files/Wave 2.dta"
cd "/Users/jimgolby/Desktop/ZB - Confidence Book/Technical Appendix/Chapter 8/Chapter 8 - Figures"

gen MOVIES = 0 if Q32 < 77
replace MOVIES = 1 if Q32 == 2
label define MOVIES 0 "Other Sources" 1 "Pop Culture"
label values MOVIES MOVIES

generate Q11T =.
replace Q11T = 0 if Q11 > 2
replace Q11T = 1 if Q11 < 3
gen CONFIDENCE = Q11T
label define Confidence 0 "Not Confident" 1 "Confident"
label values Q11T Confidence

gen AGE2 = 1 if AGE7 < 77
replace AGE2 = 0 if AGE7 < 3
label define AGE2 0 "18-34 years old" 1 "35 years or older"
label values AGE2 AGE2

***Figure 8.1***
graph bar (mean) MOVIES, over(AGE7, label(labsize(small))) bar(1, fcolor(gs6) ) blabel(bar, color(black) format(%3.2f)) ytitle(% Gets Most Military Knowledge From Pop Culture) ytitle(, size(medsmall) margin(right)) yscale(range(0 0.2)) ylabel(#6) name(Movies, replace) graphregion(fcolor(white)) plotregion(fcolor(white) lcolor(black) lalign(outside)) subtitle(Age, size(medsmall) color(black) position(6) orientation(horizontal) margin(top)) scheme(s1mono)
graph export Fig81.png, replace

***Figure 8.2***
mean CONFIDENCE [pweight = weight2], over(MOVIES AGE2)
set obs 4511
set obs 4512
set obs 4513
set obs 4514
replace CaseId = 20001 in 4511
replace CaseId = 20002 in 4512
replace CaseId = 20003 in 4513
replace CaseId = 20004 in 4514
gen meanCONFIDENCE = .567 if CaseId == 20001
replace meanCONFIDENCE = .728 if CaseId == 20003
replace meanCONFIDENCE = .671 if CaseId == 20002
replace meanCONFIDENCE = .637 if CaseId == 20004
gen lowCONFIDENCE = .526 if CaseId == 20001
replace lowCONFIDENCE = .706 if CaseId == 20003
replace lowCONFIDENCE = .587 if CaseId == 20002
replace lowCONFIDENCE = .540 if CaseId == 20004
gen hiCONFIDENCE = .607 if CaseId == 20001
replace hiCONFIDENCE = .750 if CaseId == 20003
replace hiCONFIDENCE = .755 if CaseId == 20002
replace hiCONFIDENCE = .734 if CaseId == 20004
gen P_MOVIES = 1 if CaseId == 20001
replace P_MOVIES = 2 if CaseId == 20002
replace P_MOVIES = 3 if CaseId == 20003
replace P_MOVIES = 4 if CaseId == 20004
gen meanCONFIDENCE2 = .57 if CaseId == 20001
replace meanCONFIDENCE2 = .73 if CaseId == 20003
replace meanCONFIDENCE2 = .67 if CaseId == 20002
replace meanCONFIDENCE2 = .64 if CaseId == 20004

label define P_MOVIES 1 "Other Sources" 2 "Pop Culture" 3 "Other Sources" 4 "Pop Culture"
label values P_MOVIES P_MOVIES

twoway (scatter meanCONFIDENCE P_MOVIES, mcolor(black) msymbol(circle) mlabel(meanCONFIDENCE2)) (rcap lowCONFIDENCE hiCONFIDENCE P_MOVIES, lcolor(black) lwidth(thin)), ylabel(0.5(0.05)0.80) yscale(range(0.5 0.8)) xscale(range(0.5 4.5)) ytitle(% Confidence in the Military) ytitle(, size(medsmall) margin(right)) ylabel(#6) name(Movies2, replace) graphregion(fcolor(white)) plotregion(fcolor(white) lcolor(black) lalign(outside)) xlabel(, labels valuelabel) scheme(s1mono) legend(off) xtitle(18-34 Years Old                                      35+ Years Old, color(black))
graph export Fig82.png, replace
**********

clear all

use "/Users/jimgolby/Desktop/ZB - Confidence Book/Technical Appendix/Data Files/MTF Aggregate.dta"

***Figure 8.3***
twoway (line willchange var1, lcolor(gs0) lpattern(longdash))(line defwillchange var1, lcolor(gs0) lpattern(shortdash))(line confchange var1, lcolor(gs0) lpattern(solid)) , ytitle(% Point Change From Previous Year) ytitle(, size(medsmall) margin(sides)) yline(0, lwidth(vthin) lcolor(gs8%75)) ylabel(, nogrid) xtitle(Year) xtitle(, size(medsmall) margin(top)) legend(order(1 "Will Probably Join" 2 "Will Definitely Join" 3 "Military Doing a Good Job") size(medsmall) region(lcolor(none))) scheme(s1mono)
graph export Fig83.png, replace
 
cor confchange willchange defwillchange

***Figure 8.4***
twoway (line good2 var1, lcolor(gs0) lpattern(solid)) (line fair2 var1, lcolor(gs0) lpattern(longdash)) (line poor2 var1, lcolor(gs0) lpattern(shortdash)), ytitle(% of Seniors Saying They Definitely Will Join) ytitle(, size(medsmall) margin(sides)) ylabel(0(5)25) xtitle(Year) xtitle(, size(medsmall) margin(top)) legend(order(1 "Good" 2 "Fair" 3 "Poor") size(medsmall) region(lcolor(none))) name(pic1, replace) subtitle(Definitely Will Join the Military) scheme(s1mono)

twoway (line good var1, lcolor(gs0) lpattern(solid)) (line fair var1, lcolor(gs0) lpattern(longdash)) (line poor var1, lcolor(gs0) lpattern(shortdash)), ytitle(% of Seniors Saying They Probably Will Join) ytitle(, size(medsmall) margin(sides)) ylabel(0(5)25) xtitle(Year) xtitle(, size(medsmall) margin(top)) legend(nobox lcolor() region(fcolor(none) lcolor(white) lwidth(none))) name(pic2, replace) subtitle(Probably Will Join the Military) scheme(s1mono)

graph combine pic1 pic2, scheme(s1mono)
graph export Fig84.png, replace
**********

clear all

use "/Users/jimgolby/Desktop/ZB - Confidence Book/Data/Final Wave 1 Survey/Wave 1 Weighted.dta" 

generate q8a = .
replace q8a = 0 if q8 < 77
replace q8a = 1 if q8 < 3

generate q33ac2 = .
replace q33ac2 = 0 if q33ac < 77
replace q33ac2 = 1 if q33ac < 3
replace q33ac2 = -1 if q33ac > 3 & q33ac < 77

generate q33c2 = .
replace q33c2 = 0 if q33c < 77
replace q33c2 = 1 if q33c < 3
replace q33c2 = -1 if q33c > 3 & q33c < 77

***Table 8.1***
tab q47 q8a if q47 < 98 & dov_assignment_a == 1 [aweight=weight], column

***Table 8.2***
tab q33ac2 q8a if dov_assignment_a == 1 [aweight=weight], column
tab q33c2 q8a if dov_assignment_a == 1 [aweight=weight], column
**********

clear all

use "/Users/jimgolby/Desktop/ZB - Confidence Book/Technical Appendix/Data Files/Wave 2.dta"

generate Q11T =.
replace Q11T = 0 if Q11 > 2
replace Q11T = 1 if Q11 < 3
gen CONFIDENCE = Q11T
label define Confidence 0 "Not Confident" 1 "Confident"
label values Q11T Confidence

gen Q40T =.
replace Q40T = 0 if Q40 < 98
replace Q40T = 1 if Q40 == 1

gen VET = VETERAN * (-1)

***Table 8.1***
tab Q40 Q11T if Q40 < 98 & P_ASSIGN1 == 1 [aweight=weight2], column

***Table 8.3***
tab Q40 VETERAN if Q40 < 98 & VETERAN < 3 & P_ASSIGN1 == 1 [aweight=weight2], column
tab Q40 Q37 if Q40 < 98 & Q37 < 3 & P_ASSIGN1 == 1 [aweight=weight2], column
tab Q40 Q38 if Q40 < 98 & Q38 < 3 & P_ASSIGN1 == 1 [aweight=weight2], column
tab Q40 Q39 if Q40 < 98 & Q39 < 3 & P_ASSIGN1 == 1 [aweight=weight2], column

***Figure 8.5***
graph bar (mean) Q40T [pweight = weight2] if Q11 < 77 & VETERAN < 3 & P_ASSIGN1 == 1, over(Q11, label(angle(vertical) labsize(vsmall))) over(VETERAN, relabel(1 Veteran 2 Civilian) label(labsize(small))) bar(1, fcolor(gs6)) blabel(bar, color(black) format(%3.2f)) ytitle(% Who Would Advise a Family Member to Join) ytitle(, size(vsmall)) yscale(range(0 1)) ylabel(#6) name(Vet, replace) graphregion(fcolor(white) lcolor(white) lwidth(thin) lalign(outside) ifcolor(none) ilcolor(none)) plotregion (fcolor(white) lcolor(black) lpattern(solid) lalign(outside) ifcolor(none)) scheme(s1mono)
graph export Fig85.png, replace
**********

clear all

set maxvar 10000

use "/Users/jimgolby/Desktop/ZB - Confidence Book/Technical Appendix/Data Files/Defense Spending.dta"

***Figure 8.6***
twoway (line defensespendingistoolow year, lcolor(gs5) lpattern(solid)) (line greatdealofconfidenceinmilitary year, lcolor(gs5) lpattern(longdash)), ytitle(Percentage of Respondents) ytitle(, size(medsmall) color(black) margin(right)) yscale(range(0 0.5)) ylabel(#6) xtitle(Year) xtitle(, size(medsmall) color(black) margin(top)) xscale(log) legend(nostack rows(2) size(small) color(black) region(lcolor(white))) graphregion(fcolor(white) lcolor(none) ilcolor(none)) plotregion(fcolor(white) lcolor(black) lalign(outside)) scheme(s1mono)
graph export Fig86.png, replace

***Table 8.4***
reg logtoolow logconf Post911 Rep_President waronset logdeficit logdodbudget
reg logtoolow logconf Rep_President waronset logdeficit logdodbudget if year < 2002
reg logtoolow logconf Rep_President waronset logdeficit logdodbudget if year < 2002 & y1981 == 0
reg logtoolow logconf Rep_President waronset logdeficit logdodbudget if year > 2001
**********

clear all

import spss using "/Users/jimgolby/Desktop/ZB - Confidence Book/Data/anes_timeseries_cdf.sav"

gen YEAR = VCF0004 if VCF0004 == 1980
replace YEAR = VCF0004 if VCF0004 == 1984
replace YEAR = VCF0004 if VCF0004 == 1988
replace YEAR = VCF0004 if VCF0004 == 1992
replace YEAR = VCF0004 if VCF0004 == 1996
replace YEAR = VCF0004 if VCF0004 == 2000
replace YEAR = VCF0004 if VCF0004 == 2004
replace YEAR = VCF0004 if VCF0004 == 2008
replace YEAR = VCF0004 if VCF0004 == 2012
replace YEAR = VCF0004 if VCF0004 == 2016

gen DEM = 0
replace DEM = 1 if VCF0303 == 1
gen IND = 0
replace IND = 1 if VCF0303 == 2
gen REP = 0
replace REP = 1 if VCF0303 == 3

twoway (lfitci VCF0843 VCF0213 if VCF0843 < 8 & YEAR < 2004 & REP == 1 [pweight = VCF0009z], fcolor(%50) clpattern(dash)) (lfitci VCF0843 VCF0213 if VCF0843 < 8 & YEAR > 2000 & REP == 1 [pweight = VCF0009z], fcolor(%50)), title (Republicans) ylabel(1(1)7) name(Rep, replace) xlabel(, nogextend) graphregion(fcolor(white) lcolor(white) lwidth(thin) lalign(outside) ifcolor(none) ilcolor(none)) plotregion (fcolor(white) lcolor(black) lpattern(solid) lalign(outside) ifcolor(none)) scheme(s1mono) legend(order(1 "95% CI" 2 "Pre-9/11" 3 "95% CI" 4 "Post-9/11"))

twoway (lfitci VCF0843 VCF0213 if VCF0843 < 8 & YEAR < 2004 & DEM == 1 [pweight = VCF0009z], fcolor(%50) clpattern(dash)) (lfitci VCF0843 VCF0213 if VCF0843 < 8 & YEAR > 2000 & DEM == 1 [pweight = VCF0009z], fcolor(%50)), title (Democrats) ylabel(1(1)7) name(Dem, replace) xlabel(, nogextend) graphregion(fcolor(white) lcolor(white) lwidth(thin) lalign(outside) ifcolor(none) ilcolor(none)) plotregion (fcolor(white) lcolor(black) lpattern(solid) lalign(outside) ifcolor(none)) scheme(s1mono) legend(order(1 "95% CI" 2 "Pre-9/11" 3 "95% CI" 4 "Post-9/11"))

graph combine Dem Rep, scheme(s1mono) name(support, replace)
graph export Fig87.png, replace
**********

clear all

use "/Users/jimgolby/Desktop/ZB - Confidence Book/Technical Appendix/Data Files/Wave 2.dta"

generate PID3 =.
replace PID3 = 1 if PARTYID < 4
replace PID3 = 2 if PARTYID == 4
replace PID3 = 3 if PARTYID > 4 & PARTYID < 8 

label define PID3 1 "Democrat" 2 "Independent" 3 "Republican"
label values PID3 PID3

generate Q11T =.
replace Q11T = 0 if Q11 > 2
replace Q11T = 1 if Q11 < 3

gen Q40T =.
replace Q40T = 0 if Q40 < 98
replace Q40T = 1 if Q40 == 1

gen CONFIDENCE = Q11T
label define Confidence 0 "Not Confident" 1 "Confident"
label values Q11T Confidence

gen Q4B2 =.
replace Q4B2 = 0.5 if Q4B < 77
replace Q4B2 = 1 if Q4B < 3
replace Q4B2 = 0 if Q4B > 3 & Q4B < 77
gen Q4AB2 =.
replace Q4AB2 = 0.5 if Q4AB < 77
replace Q4AB2 = 1 if Q4AB < 3
replace Q4AB2 = 0 if Q4AB > 3 & Q4AB < 77

gen Q4D2 =.
replace Q4D2 = 0.5 if Q4D < 77
replace Q4D2 = 1 if Q4D < 3
replace Q4D2 = 0 if Q4D > 3 & Q4D < 77
gen Q4AD2 =.
replace Q4AD2 = 0.5 if Q4AD < 77
replace Q4AD2 = 1 if Q4AD < 3
replace Q4AD2 = 0 if Q4AD > 3 & Q4AD < 77

***Table 8.5***
***Military Receives Too Much***
tab Q4B2 Q11T if P_ASSIGN1 == 1 [aweight=weight2], column
***Military Receives Too Little***
tab Q4AB2 Q11T if P_ASSIGN1 == 1 [aweight=weight2], column

***Table 8.6***
***Cut State to Increase DoD***
tab Q4D2 Q11T if P_ASSIGN1 == 1 [aweight=weight2], column
***Cut DoD to Increase State***
tab Q4AD2 Q11T if P_ASSIGN1 == 1 [aweight=weight2], column

***Figure 8.8***
graph bar (mean) Q4D2 [pweight = weight2] if Q11 < 77, over(CONFIDENCE, relabel(1 Not_Confident 2 Confident) label(labcolor("black") angle(vertical) labsize(small))) over(PID3) bar(1, fcolor(gs6)) blabel(bar, color(black) format(%3.2f)) ytitle(Mean Support for Cutting State to Fund DoD) ytitle(, size(medsmall)) yscale(range(0 1)) ylabel(#6) name(CutState, replace) graphregion(fcolor(white)) plotregion(fcolor(white) lcolor(black) lalign(outside)) yline(0.5, lcolor(gs10%75))

graph bar (mean) Q4AD2 [pweight = weight2] if Q11 < 77, over(CONFIDENCE, relabel(1 Not_Confident 2 Confident) label(labcolor("black") angle(vertical) labsize(small))) over(PID3) bar(1, fcolor(gs6)) blabel(bar, color(black) format(%3.2f)) ytitle(Mean Support for Cutting DoD to Fund State) ytitle(, size(medsmall)) yscale(range(0 1)) ylabel(#6) name(CutDoD, replace) graphregion(fcolor(white)) plotregion(fcolor(white) lcolor(black) lalign(outside)) yline(0.5, lcolor(gs10%75))

graph combine CutState CutDoD, scheme(s1mono)
graph export Fig88.png, replace

***Figure 8.9***
graph pie [pweight = weight2] if Q2 < 77 & Q11 < 77, over(Q2) pie(1, color(gs14)) pie(2, color(gs12)) pie(3, color(gs10)) pie(4, color(gs8)) pie(5, color(gs6) explode(large)) pie(6, color(gs4)) plabel(_all percent, color(black) format(%2.0f)) line(lcolor(black) lwidth(vthin) lalign(outside)) intensity(inten50) title(Department of Defense) note(, color(white) fcolor(white) lcolor(white)) legend(on rows(2) size(small) box fcolor(white) lcolor(white) region(fcolor(none) lcolor(none) lwidth(none))) name(Q2Pic, replace) graphregion(margin(medium) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))

graph pie [pweight = weight2] if Q2A < 77 & Q11 < 77, over(Q2A) pie(1, color(gs14)) pie(5, color(gs6)) pie(3, color(gs10)) pie(4, color(gs8)) pie(2, color(gs12) explode(large)) pie(6, color(gs4)) plabel(_all percent, color(black) format(%2.0f)) line(lcolor(black) lwidth(vthin) lalign(outside)) intensity(inten50) title(Department of State) note(, color(white) fcolor(white) lcolor(white)) legend(on rows(2) size(small) box fcolor(white) lcolor(white) region(fcolor(none) lcolor(none) lwidth(none))) name(Q2APic, replace) graphregion(margin(medium) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))

graph combine Q2Pic Q2APic, scheme(s1mono)
graph export Fig89.png, replace

***Figure 8.10***
graph pie [pweight = weight2] if Q2 < 77 & Q11 < 77, over(Q2) pie(1, color(gs14)) pie(2, color(gs12)) pie(3, color(gs10)) pie(4, color(gs8)) pie(5, color(gs6) explode(large)) pie(6, color(gs4)) plabel(_all percent, color(black) format(%2.0f)) line(lcolor(black) lwidth(vthin) lalign(outside)) intensity(inten50) by(, title() subtitle() note(, color(white) fcolor(white) lcolor(white))) by(, legend(on)) legend(rows(2) size(small) box fcolor(white) lcolor(white) region(fcolor(none) lcolor(none) lwidth(none))) by(, graphregion(margin(zero) fcolor(white) lcolor(none) ifcolor(none) ilcolor(white)) plotregion(fcolor(white) ifcolor(white))) by(Q11) subtitle(, color(black) position(12) fcolor(white) lcolor(white))
graph export Fig810.png, replace
